package com.base.component.ai.workflow.result;

import java.util.Map;

import org.springframework.stereotype.Component;

import com.base.component.ai.agent.bo.ContextBO;
import com.base.component.ai.agent.bo.ContextParamBO;
import com.base.component.ai.agent.utils.PromptChatUtils;

@Component
public class NodeResultTextSplit<MSG,AP extends ContextParamBO,PP> implements NodeResult<MSG,AP,PP> {

	@Override
	public boolean support(String fieldName) {
		return "textSplit".equals(fieldName);
	}

	@Override
	public void execute(ContextBO<MSG, AP, PP> context,Map<String,Object> params) {
		for(String key:params.keySet()) {
			String text=String.valueOf(params.get(key));
			StringBuilder sb=new StringBuilder();
			for(int i=0;i<text.length();i++) {
				sb.append(text.charAt(i));
				PromptChatUtils.handleTextFrame(sb, (t)->{
					context.getFrameConsumer().accept(t);
				});
			}
			context.getFrameConsumer().accept(sb.toString());
		}
	}
	
}
